package mspbots.next.ticket.core.grader;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.log4j.Log4j2;
import mspbots.next.ticket.core.data.rules.Rule;
import mspbots.next.ticket.core.points.PointResult;
import reactor.core.publisher.Mono;

import java.time.Duration;

/**
 * com.mspbots.core.ticketai.service.GradeRuleInterceptorRegistration
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/8/20
 */
public class GradeRuleInterceptorRegistration {

    private final String name;
    private final GradeRuleInterceptor interceptor;

    private Rule rule;

    public GradeRuleInterceptorRegistration(String interceptorName,
                                            GradeRuleInterceptor interceptor) {
        this.interceptor = interceptor;
        this.name = interceptorName;
    }

    public Mono<GradeRuleInterceptorRegistration> prepare(Rule rule) {
        this.rule = rule;
        return this.getInterceptor().prepare(this);
    }

    public Mono<PointResult> scoring(JsonNode entity) {
        return this.getInterceptor().scoring(entity)
                .timeout(Duration.ofMillis(200));
    }

    public Rule getRule() {
        return this.rule;
    }

    public String getName() {
        return this.name;
    }

    public GradeRuleInterceptor getInterceptor() {
        return this.interceptor;
    }

}
